package net.qiyuesuo.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.qiyuesuo.service.FileService;
import net.qiyuesuo.service.impl.FileServiceImpl;

/**
 * 下载文件接口
 * @author Administrator
 *
 */
public class DownLoadFileServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private FileService fileService = new FileServiceImpl();
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		String fileKey =  req.getParameter("fileKey");
		byte[] bytes = fileService.getFileThrougnBytes(fileKey);
		try(ServletOutputStream output = res.getOutputStream();){
			output.write(bytes);
			output.flush();
			logger.info("下载uuif为："+fileKey+"的文件");
		}
	}
}
